<?php if (!defined('THINK_PATH')) exit();?><!-- 会话列表 -->
<?php $rand = round(microtime(true),3)*1000;?>
<table id="sessionList_<?php echo ($rand); ?>" class="easyui-datagrid" title="<?php echo ($currentpos); ?>" data-options="
	fit:true,rownumbers:true,animate:true,fitColumns:true,
	url:'<?php echo U('session/index',array('uid'=>I('id',0)));?>',idField:'id',border:false,
	toolbar:'#sessionToolbar_<?php echo ($rand); ?>',pagination:true,singleSelect:true,pageSize:20,nowrap:false">
<thead>
	<tr>
		 <!--<th data-options="field:'logosmall',width:20,align:'center',formatter:buildFace">头像</th>-->
		<th data-options="field:'sid',width:1,align:'left'">群ID</th>
		<th data-options="field:'name',width:5,align:'left'">名称</th>
		<th data-options="field:'creator',width:5">创建者</th>
		<th data-options="field:'count',width:5,align:'center'">人数</th>
		<th data-options="field:'min_score',width:5,align:'center'">最低发红包额</th>
		<th data-options="field:'push_time',width:5,align:'center'">推送红包结果时间(秒)</th>
		<th data-options="field:'status_text',width:5">状态</th>
		<th data-options="field:'createtime',width:10">创建时间</th>
		<th data-options="field:'id',width:10,formatter:sessionOperateText">操作</th>
	</tr>
</thead>
</table>

<div id="sessionToolbar_<?php echo ($rand); ?>" style="padding:5px;height:auto">
	<form id="sessionSearchForm_<?php echo ($rand); ?>">
		<a href="javascript:;" onclick="sessionRefreshList_<?php echo ($rand); ?>();" class="easyui-linkbutton" data-options="iconCls:'icon-reload',plain:true">刷新</a>
		<input type="text" name="search[name]" placeholder="根据名称搜索" style="height: 20px; width: 120px;padding-left: 3px;">
		<a href="javascript:;" onclick="sessionSearch_<?php echo ($rand); ?>();" class="easyui-linkbutton" iconCls="icon-search">确定</a>		
	</form>
</div>

<!-- 编辑 -->
<div id="sessionEditBox" class="easyui-dialog" title="编辑会话"
	data-options="modal:true,closed:true,iconCls:'icon-add',
				buttons:[{text:'确定',iconCls:'icon-ok',
				handler:function(){$('#sessionEditForm').submit();}},
				{text:'取消',iconCls:'icon-cancel',
				handler:function(){$('#sessionEditBox').dialog('close');}}]"
	style="width: 600px; height: 280px;"></div>


<div id="pushEditBox" class="easyui-dialog" title="编辑会话推送"
	 data-options="modal:true,closed:true,iconCls:'icon-add',
				buttons:[{text:'确定',iconCls:'icon-ok',
				handler:function(){$('#pushConfigEditForm').submit();}},
				{text:'取消',iconCls:'icon-cancel',
				handler:function(){$('#pushEditBox').dialog('close');}}]"
	 style="width: 600px; height: 280px;"></div>s

<script type="text/javascript">
//刷新
function sessionRefreshList_<?php echo ($rand); ?>(){
	$('#sessionList_<?php echo ($rand); ?>').datagrid('reload');
}
//logo显示
function buildFace(val,row,index){
	if(!val){
		return '<div style="height:60px;padding:3px;margin:auto;"></div>';
	}else{
		return '<img src="'+val+'" height="60" style="padding:3px;">';	
	}
}
//操作格式化
function sessionOperateText(val, row, index){
	var btn = [];
		btn.push('<a href="javascript:void(0);" onclick="sessionEdit('+val+')">编辑</a>');
		btn.push('<a href="javascript:void(0);" onclick="sessionDelete('+val+','+row.uid+')">删除</a>');
//		btn.push('<a href="javascript:void(0);" onclick="pushConfig('+val+','+row.uid+')">设置推送</a>');
	return btn.join(' | ');
}
//搜索会话
function sessionSearch_<?php echo ($rand); ?>(){
	var queryParams = $('#sessionList_<?php echo ($rand); ?>').datagrid('options').queryParams;
	$.each($("#sessionSearchForm_<?php echo ($rand); ?>").form().serializeArray(), function (index) {
		queryParams[this['name']] = this['value'];
	});
	$('#sessionList_<?php echo ($rand); ?>').datagrid('load');
}
//会话编辑
function sessionEdit(id){
	if(typeof(id) !== 'number'){
		$.messager.alert('提示信息', '未选择', 'error');
		return false;
	}
	var url = '<?php echo U('session/edit');?>';
	url += url.indexOf('?') != -1 ? '&id='+id : '?id='+id;
	url += '&rand=<?php echo ($rand); ?>';
	$('#sessionEditBox').dialog({href:url});
	$('#sessionEditBox').dialog('open');
}

//会话删除 
function sessionDelete(id, uid){
	if(typeof(id) !== 'number'){
		$.messager.alert('提示信息', '未选择', 'error');
		return false;
	}
	$.messager.confirm('提示信息', '确定要删除吗？', function(result){
		if(!result) return false;
		$.post('<?php echo U('session/delete');?>', {id: id, uid: uid}, function(data){
			if(!data.status){
				$.messager.alert('提示信息', data.info, 'error');
			}else{
				sessionRefreshList_<?php echo ($rand); ?>();
				$.messager.alert('提示信息', data.info, 'info');
			}
		}, 'json');
	});
}

function pushConfig(id){
	if(typeof(id) !== 'number'){
		$.messager.alert('提示信息', '未选择', 'error');
		return false;
	}

	var url = '<?php echo U('session/pushConfig');?>';
	url += url.indexOf('?') != -1?'&id='+id : '?id='+ id;
	url += '&rand=<?php echo ($rand); ?>';

	$('#pushEditBox').dialog({href:url});
	$('#pushEditBox').dialog('open');
}
</script>